
require('../css/common/normalize.css')
require('../css/common/reset.css')
require('../css/common/property.css')
require('../css/common/basic.less')
require('../lib/fonts/iconfont.css')


//导入axios
const axios = require("axios");

//导入weui
require("weui")
const weui = require("weui.js")

//导入util
const util = require('../util/util')

//swiper插件
require('../lib/swiper/swiper-bundle.css')
const Swiper=require('../lib/swiper/swiper-bundle.js')


require('../css/home.less')

document.addEventListener('DOMContentLoaded',function(){
  
    /**
   * 0.底部导航
   */
     util.fixBottomNav('home')

  function setSwiper(){
    var mySwiper = new Swiper ('.swiper', {
      loop: true, // 循环模式选项
      autoplay: {
        delay: 1500,
        disableOnInteraction: false //不用禁止自动播放
      },
      
      // 如果需要分页器
      pagination: {
        el: '.swiper-pagination',
      }
      
    })   

}

setSwiper()
  })


// 实现后台数据的渲染

// 获取元素

const rank=document.querySelector('#rank')    //排名
const punchIn=document.querySelector('#punchIn')   //打卡天数
const insigniaNum=document.querySelector('#insigniaNum')   //徽章数
const daka=document.querySelector('#daka')   //徽章数

axios.get('http://139.9.177.51:8099/headPageInfo',{

      params: {
        userId:localStorage.getItem('userId')
      }
    }).then(function(res){
      console.log(res);

      if (res.data.status === 0) {
      //今日排名
      rank.textContent=res.data.data.rank

      // 累计运动徽章
      insigniaNum.textContent=res.data.data.insigniaNum

      //打卡
      punchIn.textContent=res.data.data.punchIn
      res.data.data.isPunch ==='true' ? daka.textContent='已打卡' : daka.textContent='今日打卡'

      //console.log(res.data.data.isPunch);
    }
  }

)

// 累计打卡的实现。就是点击今日打卡就将累积天数添加1天
//并且累计打卡变成已打卡

daka.addEventListener('click',function(){

  axios.get('http://139.9.177.51:8099/clockIn',{

      params: {
        userId:localStorage.getItem('userId')
      }
    }).then(function(res){
      console.log(res);

      if(res.data.status == 0){
        console.log(res.data.status);
        punchIn.textContent++
        daka.textContent='已打卡'
        weui.toast('打卡成功', 1000)
      }else{
        weui.toast('已打卡', 1000)

      }
      
    }
)

})

//跳转
document.querySelector('#p1').addEventListener('click',function(){
  location.href='./me-datas.html'
})

document.querySelector('#homeTrain').addEventListener('click',function(){
  location.href='./motion-train.html'
})





     